package com.accenture.adf.newcodington.module20.sample;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class SelectDemo {
	

		public static void main(String[] args) {
			try{
				//Obtaining a connection
				Connection con = ConnectionToDBDemo.getConnection();
				if(con != null)
				{
				System.out.println("Connection successfully established!");
				}
				
				//Creating a PreparedStatement with a query "select * from Employee" 
				PreparedStatement pStmt = con.prepareStatement("select * from Student");
				
				//Executing this query using executeQuery()
				ResultSet rs = pStmt.executeQuery();
				
				//Process the resultSet and print all records on console
				System.out.println("Student ID	Name		Course ID");
				while(rs.next())
				{
					System.out.println(rs.getString(1)+"		"+ rs.getString(2) + "		" + rs.getString(3));
					
				}
				//Closing the connection
				con.close();
				
			}catch (Exception e){
				System.out.println(e.getMessage());
			}

		}
}

